package com.yc154.springmvc1;

import com.yc154.springmvc1.demos.web.DatteConvertor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication
public class SpringMvc1Application implements WebMvcConfigurer {

    public static void main(String[] args) {
        SpringApplication.run(SpringMvc1Application.class, args);
    }

    @Value("${upload.webPath}")
    String webPath;
    @Value("${upload.diskPath}")
    String diskPath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(webPath + "**")
                .addResourceLocations("file:" + diskPath);
    }

    @Override
    public void addFormatters(FormatterRegistry registry) {
        // 格式化与类型转换的配置
        registry.addConverter( new DatteConvertor());
    }

    // apache 的文件上传解析器
//    @Bean
//    public MultipartResolver getMultipartResolver() {
//        return new CommonsMultipartResolver();
//    }

}
